<?php

namespace app\index\service;

class LoginUserService
{
    private static $session_key = 'activity_user';

    public static function login(array $user_data)
    {
        session(self::$session_key, $user_data);
    }

    public static function get($key = null)
    {
        if (is_null($key)) {
            return session(self::$session_key) ?: [];
        }
        return @session(self::$session_key)[$key] ?? null;
    }

    public static function logout()
    {
        session(self::$session_key, null);
    }

    public static function ifLogin()
    {
        return boolval(self::get('id'));
    }

}